package com.chery.media.ui.setting.gps

import android.content.Context
import android.location.LocationManager
import android.provider.Settings
import com.chery.media.library.base.BaseViewModel
import com.chery.media.library.extend.livedata.BooleanLiveData

class GpsViewModel: BaseViewModel() {

    val gpsStatus = BooleanLiveData()

    /**
     * 获取GPS开关
     */
    fun getGpsStatus(context: Context){
        val resolver = context.contentResolver
        val status = Settings.Secure.isLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER)
        gpsStatus.value = status
    }

    /**
     * 设置Gps 状态
     */
    fun setGpsStatus(context: Context, isOpen: Boolean){
        val resolver = context.contentResolver
        Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER, isOpen)
    }

}